package cn.gglol.jvvtool.controller.jedis;

import cn.gglol.jvvtool.entity.User;
import cn.gglol.jvvtool.entity.jedis.cache.CacheTime;
import cn.gglol.jvvtool.service.jedis.CacheService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Set;

/**
 * @author jvvtao
 * @version 1.0
 * @project Name: jvvtool
 * @file Name: CacheController
 * @desc Jedis Cache Controller
 * @date 2021/9/1
 * @time 23:11
 * @by IDE: IntelliJ IDEA
 */
@RestController
@RequestMapping("/jedis/cache")
public class CacheController {

    @Resource
    private CacheService cacheService;

    @RequestMapping("/getTime")
    public CacheTime getTime(@RequestParam(defaultValue = "5") Integer seconds) {
        CacheTime cacheTime = new CacheTime();
        cacheTime.setCache(cacheService.getTime(seconds));
        cacheTime.setCache2(cacheService.getTime2(seconds));
        cacheTime.setNow(LocalTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME));
        return cacheTime;
    }

    @RequestMapping("/getUser")
    public User getUser(@RequestParam Long id) {
        return cacheService.getUser(id);
    }

    @RequestMapping("/getUser2")
    public User getUser2(@RequestParam Long id) {
        return cacheService.getUser2(id);
    }

    @RequestMapping("/getUserList")
    public List<User> getUserList(@RequestParam int count) {
        return cacheService.getUserList(count);
    }

    @RequestMapping("/getUserSet")
    public Set<User> getUserSet(@RequestParam int count) {
        return cacheService.getUserSet(count);
    }

    @RequestMapping("/getUserHashSet")
    public Set<User> getUserHashSet(@RequestParam int count) {
        return cacheService.getUserHashSet(count);
    }
}
